import request from '@/utils/request'  // 封装的axios实例

export function getModulesByProjectId(data) {
    return request({
        url: '/permissions/getPermissionTree',
        method: 'post',
        data
    })
}

export function getModulesByCode(data) {
    return request({
        url: '/permissions/getPermissionByCode',
        method: 'post',
        data
    })
}


export function addPermission(data) {
    return request({
        url: '/permissions/addPermission',
        method: 'post',
        data
    })
}

export function transformData(data) {
    return data.map(item => ({
        id: item.permissionCode, // 将 nodeId 映射为 id
        label: item.permissionName, // 将 name 映射为 label
        icon: item.icon,
        children: item.children.length ? transformData(item.children) : [] // 递归转换 childrenNodes 为 children
    }));
}
